/*
 * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cc.siyecao.mapper.wrapper;

import cc.siyecao.mapper.function.Fn;

/**
 * Lambda 语法使用 AbstractWrapper
 * <p>统一处理解析 lambda 获取 column</p>
 */
@SuppressWarnings("serial")
public class LambdaWrapper<T> extends AbstractLambdaWrapper<Fn<T, ?>, LambdaWrapper<T>, CompareWrapper<T, Fn<T, ?>>, FuncWrapper<T, Fn<T, ?>>, T> {
    public LambdaWrapper() {
        clear();
    }

    @Override
    protected CompareWrapper<T, Fn<T, ?>> nestedInstance(String currentType) {
        return new CompareWrapper<T, Fn<T, ?>>( currentType ) {
            @Override
            public String columnName(Fn<T, ?> column) {
                return column.toColumnName();
            }

            @Override
            public String fieldName(Fn<T, ?> column) {
                return column.toField();
            }
        };
    }

    @Override
    protected FuncWrapper<T, Fn<T, ?>> funcInstance() {
        return new FuncWrapper<T, Fn<T, ?>>() {
            @Override
            public String columnName(Fn<T, ?> column) {
                return column.toColumnName();
            }

            @Override
            public String fieldName(Fn<T, ?> column) {
                return column.toField();
            }
        };
    }

    @Override
    public String columnName(Fn<T, ?> column) {
        return column.toColumnName();
    }

    @Override
    public String fieldName(Fn<T, ?> column) {
        return column.toField();
    }

    /**
     * 清除所有设置
     */
    @Override
    public void clear() {
        endSql.toEmpty();
        sqlComment.toEmpty();
        startSql.toEmpty();
        criterias.clear();
        setCriteria.clear();
        currentType.setStringValue( "normal" );
        orderByClause.toNull();
        groupByClause.toEmpty();
        sqlSelect.toEmpty();
        distinct = false;
    }
}
